﻿package mortal.game.view.common.tooltip.tooltips
{
    import baseEngine.core.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;

    public class ToolTipBaseItem3D extends ToolTipBaseItem implements IWindow3D, IToolTip3D
    {
        protected var _txtBind:GTextFiled;
        protected var _3dBg:Bitmap;
        protected var _3dObj:Pivot3D;
        protected var _rect3D:Rect3DObject;
        protected var _img2d:Img2D;
        protected var _3dRectWidth:int = 200;
        protected var _3dRectHeight:int = 200;
        protected var _contentTopOf3DSprite:Sprite;

        public function ToolTipBaseItem3D()
        {
            this._contentTopOf3DSprite = new Sprite();
            return;
        }// end function

        override protected function createChildren() : void
        {
            super.createChildren();
            _txtLv.y = 28;
            this._txtBind = UIFactory.gTextField("", 80, 80, 120, 20, contentContainer2D);
            this._3dBg = UIFactory.bitmap(ImagesConst.ToolTip3DBg2, -5, 102);
            contentContainer2D.addChildAt(this._3dBg, 0);
            _txtDesc.y = 284 + 85;
            this.addEventListener(Event.ADDED_TO_STAGE, this.addToStageHandler);
            this.addEventListener(Event.REMOVED_FROM_STAGE, this.removeFromeStageHandler);
            return;
        }// end function

        public function get contentContainer() : Sprite
        {
            return this;
        }// end function

        protected function addToStageHandler(event:Event) : void
        {
            this.dispatchEvent(new WindowEvent(WindowEvent.SHOW_END));
            return;
        }// end function

        protected function removeFromeStageHandler(event:Event) : void
        {
            this.dispatchEvent(new WindowEvent(WindowEvent.CLOSE_END));
            return;
        }// end function

        public function updatePosition() : void
        {
            this.dispatchEvent(new WindowEvent(WindowEvent.POSITIONCHANGE));
            return;
        }// end function

        public function get contentTopOf3DSprite() : Sprite
        {
            return this._contentTopOf3DSprite;
        }// end function

        override public function set data(param1) : void
        {
            super.data = param1;
            var _loc_2:* = _data.itemInfo.bind == 1;
            var _loc_3:* = ItemsUtil.isBind(_data);
            if (_loc_2)
            {
                this._txtBind.textColor = 16711680;
                this._txtBind.text = "[" + Language.getString(20206) + "]";
            }
            else if (_loc_3)
            {
                this._txtBind.textColor = 16711680;
                this._txtBind.text = "[" + Language.getString(20249) + "]";
            }
            else
            {
                this._txtBind.textColor = 65280;
                this._txtBind.text = "[" + Language.getString(20205) + "]";
            }
            return;
        }// end function

        protected function add3DModel() : void
        {
            var _loc_1:* = new Rectangle(this._3dBg.x + paddingLeft + 19, this._3dBg.y + paddingTop + 36, this._3dRectWidth, this._3dRectHeight);
            this._rect3D = Rect3DManager.instance.registerWindow(true, _loc_1, this, true);
            Rect3DManager.instance.windowShowHander(null, this);
            if (this._3dBg.bitmapData)
            {
                if (!this._img2d)
                {
                    this._img2d = new Img2D(null, this._3dBg.bitmapData, new Rectangle(19, 36, this._3dRectWidth, this._3dRectHeight), false);
                    this._img2d.autoDispose = false;
                }
                this._rect3D.addImg(this._img2d);
            }
            this.set3dModel();
            this.update3dModelToStage();
            return;
        }// end function

        protected function update3dModelToStage() : void
        {
            this._rect3D.addObject3d(this._3dObj, this._3dRectWidth / 2, this._3dRectHeight - 20);
            this.dispatchEvent(new WindowEvent(WindowEvent.SHOW));
            this.updatePosition();
            return;
        }// end function

        protected function set3dModel() : void
        {
            this._3dObj = FrObjectPool.getObject(RoleModelPlayer, this);
            (this._3dObj as RoleModelPlayer).entityInfo = Cache.instance.role.roleEntityInfo;
            (this._3dObj as RoleModelPlayer).scaleAll = 1.4;
            (this._3dObj as RoleModelPlayer).setRenderList(this._rect3D.renderList);
            return;
        }// end function

        protected function modleLoadedHandler(param1 = null) : void
        {
            return;
        }// end function

    }
}
